<?php
/**
 * 用户行为
 * Created by PhpStorm.
 * User: caichunmin
 * Date: 2017/1/5
 * Time: 15:06
 */

namespace YMApi\Model;


use Think\Model;

class UserBehaviorModel extends Model {

    /**
     * 新加用户行为
     * @param int $user_id 用户id
     * @param int $item_id 商品id
     * @param int $wid 仓库id
     * @param string $bhv_type 行为类型
     * @param int $bhv_amt 用户对物品的评分、消费、观看时长等。
     * @param int $bhv_cnt 行为次数，默认为1，消费可以埋购买件数
     * @return bool
     */
    public function add_user_behavior($user_id, $item_id, $wid, $bhv_type, $bhv_amt=1, $bhv_cnt=1){
        //参数为空
        if(!$user_id || !$item_id || !$bhv_type)
            return  false;

        $storage = M('goods_storage')->field('id')->where(array('goods_id'=>$item_id,'wid'=>$wid))->find();

        $data['user_id'] = $user_id;
        $data['item_id'] = $item_id;
        $data['wid'] = $wid;
        $data['storageid'] = $storage['id'] ? $storage['id'] : 0;
        $data['bhv_type'] = $bhv_type;
        $data['bhv_amt'] = $bhv_amt;
        $data['bhv_cnt'] = $bhv_cnt;
        $data['bhv_datetime'] = date('Y-m-d H:i:s');
        return $this->add($data);
    }
}